using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.Expression.Controls
{
	public sealed class LayoutPathCapacityConverter : TypeConverter
	{
		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
		{
			if (sourceType != typeof(string))
			{
				if (sourceType != typeof(double))
				{
					return base.CanConvertFrom(context, sourceType);
				}
			}
			return true;
		}
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
		{
			string text = value as string;
			if (text != null)
			{
				string text2 = text.ToUpper(CultureInfo.get_InvariantCulture());
				if (text2 == "AUTO")
				{
					return double.NaN;
				}
				return double.Parse(text, culture);
			}
			else
			{
				if (value is double)
				{
					return value;
				}
				return base.ConvertFrom(context, culture, value);
			}
		}
		public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
		{
			if (destinationType != typeof(string) || !(value is double))
			{
				return base.ConvertTo(context, culture, value, destinationType);
			}
			double num = (double)value;
			if (double.IsNaN(num))
			{
				return "Auto";
			}
			return num.ToString(culture);
		}
	}
}
